﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;

namespace Alfred
{
	class Commande
	{
        public string lastCommand { get; set; }
        public DateTime lastDate { get; set; }

        public void Execute(string command,SpeechRecognizedEventArgs e, ASR ASR, Alfred alfred)
        {
            switch (command)
			{
				case "START":
					alfred.WakeUp();
					break;

				case "STOP":
					alfred.Stop();
                    break;

                case "SCENARIO":
                    alfred.launchMode(e.Result.Semantics["mode"].Value.ToString());
                    break;

                case "STOP_LISTENING":
                    alfred.GoToSleep();
                    break;

				case "TIME":
					alfred.Time();
					break;

				case "SEARCH":
					ASR.ASREngine.Dispose();
					ASR.configEngine();
					ASR.StartEngineDictation();
					break;

                case "SAVE_RAPPEL":
                    ASR.ASREngine.Dispose();
                    ASR.configEngine();
                    alfred.Speak("Que voulez-vous que je vous rappelle ?");
                    lastDate = StringUtils.FormatStringDay(e.Result.Semantics["day"].Value.ToString());
                    ASR.StartEngineDictation();
                    break;

				case "PLAY":
					alfred.PlayMovie("aa");
					break;

                case "MAILS_COUNT":
                    alfred.Speak(alfred.config.mail.getNbNewMailsString());
                    break;

                case "MAILS_LIST_FROM":
                    alfred.Speak(alfred.config.mail.getFromNewMailsString());
                    break;

                case "MAIL_READ":
                    alfred.Speak(alfred.config.mail.getContentNewMailString(alfred.config.mail.newMails.First()));
                    break;

                case "PLAYLIST_ARTIST":
                    alfred.Playlist(e.Result.Semantics["artist"].Value.ToString(),1);
                    break;

                case "PLAYLIST_GENRE":
                    alfred.Playlist(e.Result.Semantics["genre"].Value.ToString(),2);
                    break;

				case "ALLUME":
					alfred.Light(1, e.Result.Semantics["piece"].Value.ToString());
					break;

				case "ETEINS":
					alfred.Light(0, e.Result.Semantics["piece"].Value.ToString());
					break;

				case "TURN_UP":
					alfred.Light(100, e.Result.Semantics["piece"].Value.ToString());
					break;

				case "TURN_DOWN":
					alfred.Light(10, e.Result.Semantics["piece"].Value.ToString());
					break;

				case "MOVIE_LIST":
                    string[] sep = new string[1];
                    sep[0] = "-pour";
                    alfred.GetMovieList(e.Result.Semantics["area"].Value.ToString().Split(sep, StringSplitOptions.None)[0], e.Result.Semantics["area"].Value.ToString().Split(sep, StringSplitOptions.None)[0]);
					break;

				case "MOVIE_HOUR":                    
                    sep = new string[1];
                    sep[0] = "-pour";
                    alfred.GetMovieHours(e.Result.Semantics["film"].Value.ToString().Split(sep, StringSplitOptions.None)[0], e.Result.Semantics["film"].Value.ToString().Split(sep, StringSplitOptions.None)[1]);
					break;

                case "SHOWCASE":
                    alfred.GetSCProg(StringUtils.FormatStringDay(e.Result.Semantics["day"].Value.ToString()));
                    break;

                case "SHOWCASE_ALL":
                    alfred.GetSCProg(new DateTime());
                    break;

                default:
                    return;
			}
            lastCommand = command;
        }
	}
}
